package com.zeropoint.demo.pojo;


import com.zeropoint.demo.pojo.vo.Family;
import com.zeropoint.demo.util.ArrayUtils;
import lombok.ToString;

import java.util.ArrayList;
import java.util.List;

/**
 * 人力资源标准
 */
@ToString
public class HumanResourceStandardized {


    //excel
    //16岁以下男性人数
    public int numberUnder16_m_num ;
    //16岁以下女性人数
    public int numberUnder16_w_num;
    //17-18岁男性人数
    public int numberOfAged17_18_m_num;
    //17-18岁女性人数
    public int numberOfAged17_18_w_num;
    //19-60岁男性人数
    public int numberOfAged19_60_m_num;
    //19-60岁女性人数
    public int numberOfAged19_60_w_num;
    //60岁以上男性人数
    public int numberOfOver60_m_num;
    //60岁以上女性人数
    public int numberOfOver60_w_num;

    //良好 16
    public int numberUnder16_good;
    //患慢性病 16
    public int numberUnder16_chronicDiseases;
    //患重大疾病 16
    public int numberUnder16_majorDiseases;
    //残疾 16
    public int numberUnder16_disability;
    //良好 17-18
    public int numberOfAged17_18_good;
    //患慢性病 17-18
    public int numberOfAged17_18_chronicDiseases;
    //患重大疾病 17-18
    public int numberOfAged17_18_majorDiseases;
    //残疾 17-18
    public int numberOfAged17_18_disability;
    //良好 19-60
    public int numberOfAged19_60_good;
    //患慢性病 19-60
    public int numberOfAged19_60_chronicDiseases;
    //患重大疾病 19-60
    public int numberOfAged19_60_majorDiseases;
    //残疾 19-60
    public int numberOfAged19_60_disability;
    //良好 60以上
    public int numberOfOver60_good;
    //患慢性病 60以上
    public int numberOfOver60_chronicDiseases;
    //患重大疾病 60以上
    public int numberOfOver60_majorDiseases;
    //残疾 60以上
    public int numberOfOver60_disability;

    //文盲 16
    public int numberUnder16_illiterate;
    //学龄前 16
    public int numberUnder16_pre;
    //小学 16
    public int numberUnder16_primary;
    //初中 16
    public int numberUnder16_junior;
    //高中 16
    public int numberUnder16_high;
    //大专及以上 16
    public int numberUnder16_collegeDegreeOrAbove;
    //文盲 17-18
    public int numberOfAged17_18_illiterate;
    //学龄前 17-18
    public int numberOfAged17_18_pre;
    //小学 17-18
    public int numberOfAged17_18_primary;
    //初中 17-18
    public int numberOfAged17_18_junior;
    //高中 17-18
    public int numberOfAged17_18_high;
    //大专及以上 17-18
    public int numberOfAged17_18_collegeDegreeOrAbove;
    //文盲 19-60
    public int numberOfAged19_60_illiterate;
    //学龄前  19-60
    public int numberOfAged19_60_pre;
    //小学 19-60
    public int numberOfAged19_60_primary;
    //初中 19-60
    public int numberOfAged19_60_junior;
    //高中 19-60
    public int numberOfAged19_60_high;
    //大专及以上 19-60
    public int numberOfAged19_60_collegeDegreeOrAbove;
    //文盲 60以上
    public int numberOfOver60_illiterate;
    //学龄前 60以上
    public int numberOfOver60_pre;
    //小学 60以上
    public int numberOfOver60_primary;
    //初中 60以上
    public int numberOfOver60_junior;
    //高中 60以上
    public int numberOfOver60_high;
    //大专及以上 60以上
    public int numberOfOver60_collegeDegreeOrAbove;

    //农业生产 17-18
    public int numberOfAged17_18_agriculturalProduction;
    //务工17-18
    public int numberOfAged17_18_migrantWorkers;
    //休业17-18
    public int numberOfAged17_18_closedDown;
    //待业17-18
    public int numberOfAged17_18_unemployed;
    //农业生产19-60
    public int numberOfAged19_60_agriculturalProduction;
    //务工19-60
    public int numberOfAged19_60_migrantWorkers;
    //休业19-60
    public int numberOfAged19_60_closedDown;
    //待业19-60
    public int numberOfAged19_60_unemployed;
    //农业生产60以上
    public int numberOfOver60_agriculturalProduction;
    //务工60以上
    public int numberOfOver60_migrantWorkers;
    //休业60以上
    public int numberOfOver60_closedDown;
    //待业60以上
    public int numberOfOver60_unemployed;

    //慢性疾病 16以下
    public String[] numberUnder16_chronic_disease_info;
    //重大疾病 16以下
    public String[] numberUnder16_major_disease_info;
    //残疾 16以下
    public String[] numberUnder16_disabled_info;
    //慢性疾病 17-18
    public String[] numberOfAged17_18_chronic_disease_info;
    //重大疾病 17-18
    public String[] numberOfAged17_18_major_disease_info;
    //残疾 17-18
    public String[] numberOfAged17_18_disabled_info;
    //慢性疾病 19-60
    public String[] numberOfAged19_60_chronic_disease_info;
    //重大疾病 19-60
    public String[] numberOfAged19_60_major_disease_info;
    //残疾 19-60
    public String[] numberOfAged19_60_disabled_info;
    //慢性疾病 60以上
    public String[] numberOfOver60_chronic_disease_info;
    //重大疾病 60以上
    public String[] numberOfOver60_major_disease_info;
    //残疾 60以上
    public String[] numberOfOver60_disabled_info;

    //数据汇总
    //总人口
    public static int totalPopulation;
    //16岁以下人数
    public int numberUnder16;
    //17-18岁人数
    public int numberOfAged17_18;
    //19-60岁人数
    public int numberOfAged19_60;
    //60岁以上人数
    public int numberOfOver60;
    //劳动力
    public double laborForce;
    //主要劳动力
    public double mainLaborForce;
    //文盲及学龄前
    public int illiterateAndPre;
    //文盲
    public int illiterate;
    //学龄前
    public int pre;
    //小学
    public int primary;
    //初中
    public int junior;
    //高中
    public int high;
    //大专及以上
    public int collegeDegreeOrAbove;
    //良好
    public int good;
    //患慢性病
    public int chronicDiseases;
    //患重大疾病
    public int majorDiseases;
    //残疾
    public int disability;
    //农业生产
    public int agriculturalProduction;
    //务工
    public int migrantWorkers;
    //休业
    public int closedDown;
    //待业
    public int unemployed;
    //劳动力残疾人数
    public int disabledWorkers;
    //19-60岁人数
    public int numberOfAged19_602;

    //数据整理
    // 劳动力/总人口
    public double laborTotalPopulation;
    // 文化程度
    public double education;
    // 人均文化程度
    public double educationPer;
    // 家庭健康指数
    public double familyHealth;
    // 家庭就业指数
    public double familyEmployment;
    // 人均健康指数
    public double healthPer;
    // 人均就业指数
    public double employmentPer;
    // 主要劳动力/劳动力
    public double mainForce;

    //计算结果
    // 劳动力赋值
    public double laborAssignment;
    // 文化程度赋值
    public double educationalAssignment;
    // 人均健康赋值
    public double healthAssignment;
    // 人均就业指标赋值
    public double employmentAssignment;
    // 主要劳动力/劳动力赋值
    public double mainForceAssignment;
    // 劳动力残疾比
    public double disabilityRatio;

    public HumanResourceStandardized(){}

    //人力资源标准化
    //全部标准化
    public HumanResourceStandardized(FormOne formOne){
        totalPopulation = formOne.total_people_num;
        //数据汇总
        dataSummary(formOne.family);
        //数据整理
        dataCollated();
    }

    //数据汇总
    public HumanResourceStandardized dataSummary(List<Family> familyList){

        for(Family family : familyList){
            //统计
            if(family.age.contains("16")){
                numberUnder16 ++;

                if("男".equals(family.sex)){
                    numberUnder16_m_num ++;
                }else if("女".equals(family.sex)){
                    numberUnder16_w_num ++;
                }

                //文化程度
                if(family.education.contains("文盲")){
                    illiterate++;
                    illiterateAndPre ++;
                    numberUnder16_illiterate ++;
                }else if(family.education.contains("学龄前")){
                    pre++;
                    illiterateAndPre ++;
                    numberUnder16_pre ++;
                }else if(family.education.contains("小学")){
                    primary ++;
                    numberUnder16_primary ++;
                }else if(family.education.contains("初中")){
                    junior ++;
                    numberUnder16_junior ++;
                }else if(family.education.contains("高中") || family.education.contains("中职")){
                    high ++;
                    numberUnder16_high ++;
                }else {
                    collegeDegreeOrAbove ++;
                    numberUnder16_collegeDegreeOrAbove ++;
                }


                if(isMajor(family)){
                    majorDiseases ++;
                    numberUnder16_majorDiseases ++;
                    //患重大疾病
                    numberUnder16_major_disease_info = ArrayUtils.addAllStr(numberUnder16_major_disease_info , family.major_disease_info);
                }else if(isChronic(family)){
                    chronicDiseases ++;
                    numberUnder16_chronicDiseases ++;
                    //患慢性疾病
                    numberUnder16_chronic_disease_info = ArrayUtils.addAllStr(numberUnder16_chronic_disease_info , family.chronic_disease_info);
                }else if(isDisabled(family)){
                    disability ++;
                    numberUnder16_disability ++;
                    //患残疾
                    numberUnder16_disabled_info = ArrayUtils.addAllStr(numberUnder16_disabled_info, family.disabled_info);
                }else {
                    numberUnder16_good ++;
                    good ++;
                }


            }else if(family.age.contains("17") || family.age.contains("17-18")){
                numberOfAged17_18 ++;

                if(isHealth(family)){
                    laborForce += 0.5;
                }

                if(isDisabled(family)){
                    disabledWorkers ++;
                }

                if("男".equals(family.sex)){
                    numberOfAged17_18_m_num ++;
                }else if("女".equals(family.sex)){
                    numberOfAged17_18_w_num ++;
                }

                //文化程度
                if(family.education.contains("文盲")){
                    illiterate++;
                    illiterateAndPre ++;
                    numberOfAged17_18_illiterate ++;
                }else if(family.education.contains("学龄前")){
                    pre++;
                    illiterateAndPre ++;
                    numberOfAged17_18_pre ++;
                }else if(family.education.contains("小学")){
                    primary ++;
                    numberOfAged17_18_primary ++;
                }else if(family.education.contains("初中")){
                    junior ++;
                    numberOfAged17_18_junior ++;
                }else if(family.education.contains("高中") || family.education.contains("中职")){
                    high ++;
                    numberOfAged17_18_high ++;
                }else {
                    collegeDegreeOrAbove ++;
                    numberOfAged17_18_collegeDegreeOrAbove ++;
                }

                if("农业生产".equals(family.employment)){
                    agriculturalProduction ++;
                    familyEmployment += 0.8;
                    numberOfAged17_18_agriculturalProduction ++;
                }else if("务工".equals(family.employment)){
                    migrantWorkers ++;
                    familyEmployment += 0.8;
                    numberOfAged17_18_migrantWorkers ++;
                }else if("休业".equals(family.employment)){
                    closedDown ++;
                    numberOfAged17_18_closedDown ++;
                }else if("待业".equals(family.employment)){
                    unemployed ++;
                    numberOfAged17_18_unemployed ++;
                }

                if(isMajor(family)){
                    majorDiseases ++;
                    numberOfAged17_18_majorDiseases ++;
                    //重大疾病
                    numberOfAged17_18_major_disease_info = ArrayUtils.addAllStr(numberOfAged17_18_major_disease_info , family.major_disease_info);
                }else if(isChronic(family)){
                    chronicDiseases ++;
                    numberOfAged17_18_chronicDiseases ++;
                    //慢性疾病
                    numberOfAged17_18_chronic_disease_info = ArrayUtils.addAllStr(numberOfAged17_18_chronic_disease_info ,family.chronic_disease_info);
                }else if(isDisabled(family)){
                    disability ++;
                    numberOfAged17_18_disability ++;
                    //残疾
                    numberOfAged17_18_disabled_info = ArrayUtils.addAllStr(numberOfAged17_18_disabled_info, family.disabled_info);
                }else {
                    good ++;
                    numberOfAged17_18_good ++;
                }
            }else if(family.age.contains("19") || family.age.contains("19-60")){
                numberOfAged19_60 ++;

                if(isHealth(family)){
                    laborForce += 1;
                    mainLaborForce += 1;
                }else if(isChronic(family) && !isMajor(family) && !isDisabled(family)){
                    laborForce += 0.5;
                    mainLaborForce += 0.5;
                }

                if(isDisabled(family)){
                    disabledWorkers ++;
                }

                if("男".equals(family.sex)){
                    numberOfAged19_60_m_num ++;
                }else if("女".equals(family.sex)){
                    numberOfAged19_60_w_num ++;
                }

                //文化程度
                if(family.education.contains("文盲")){
                    illiterate++;
                    illiterateAndPre ++;
                    numberOfAged19_60_illiterate ++;
                }else if(family.education.contains("学龄前")){
                    pre++;
                    illiterateAndPre ++;
                    numberOfAged19_60_pre ++;
                }else if(family.education.contains("小学")){
                    primary ++;
                    numberOfAged19_60_primary ++;
                }else if(family.education.contains("初中")){
                    junior ++;
                    numberOfAged19_60_junior ++;
                }else if(family.education.contains("高中") || family.education.contains("中职")){
                    high ++;
                    numberOfAged19_60_high ++;
                }else {
                    collegeDegreeOrAbove ++;
                    numberOfAged19_60_collegeDegreeOrAbove ++;
                }

                if("农业生产".equals(family.employment)){
                    agriculturalProduction ++;
                    familyEmployment += 1;
                    numberOfAged19_60_agriculturalProduction ++;
                }else if("务工".equals(family.employment)){
                    migrantWorkers ++;
                    familyEmployment += 1;
                    numberOfAged19_60_migrantWorkers ++;
                }else if("休业".equals(family.employment)){
                    closedDown ++;
                    numberOfAged19_60_closedDown ++;
                }else if("待业".equals(family.employment)){
                    unemployed ++;
                    numberOfAged19_60_unemployed ++;
                }

                if(isMajor(family)){
                    majorDiseases ++;
                    numberOfAged19_60_majorDiseases ++;
                    //重大疾病
                    numberOfAged19_60_major_disease_info = ArrayUtils.addAllStr(numberOfAged19_60_major_disease_info ,family.major_disease_info);
                }else if(isChronic(family)){
                    chronicDiseases ++;
                    numberOfAged19_60_chronicDiseases ++;
                    //慢性疾病
                    numberOfAged19_60_chronic_disease_info = ArrayUtils.addAllStr(numberOfAged19_60_chronic_disease_info, family.chronic_disease_info);
                }else if(isDisabled(family)){
                    disability ++;
                    numberOfAged19_60_disability ++;
                    //残疾
                    numberOfAged19_60_disabled_info = ArrayUtils.addAllStr(numberOfAged19_60_disabled_info, family.disabled_info);
                }else {
                    good ++;
                    numberOfAged19_60_good ++;
                }

            }else{
                numberOfOver60 ++;

                if(isHealth(family)){
                    laborForce += 0.5;
                    numberOfAged19_602 ++;
                }

                if(isChronic(family) && !isMajor(family) && !isDisabled(family)){
                    numberOfAged19_602 ++;
                }

                if("男".equals(family.sex)){
                    numberOfOver60_m_num ++;
                }else if("女".equals(family.sex)){
                    numberOfOver60_w_num ++;
                }

                //文化程度
                if(family.education.contains("文盲")){
                    illiterate++;
                    illiterateAndPre ++;
                    numberOfOver60_illiterate ++;
                }else if(family.education.contains("学龄前")){
                    pre++;
                    illiterateAndPre ++;
                    numberOfOver60_pre ++;
                }else if(family.education.contains("小学")){
                    primary ++;
                    numberOfOver60_primary ++;
                }else if(family.education.contains("初中")){
                    junior ++;
                    numberOfOver60_junior ++;
                }else if(family.education.contains("高中") || family.education.contains("中职")){
                    high ++;
                    numberOfOver60_high ++;
                }else {
                    collegeDegreeOrAbove ++;
                    numberOfOver60_collegeDegreeOrAbove ++;
                }

                if("农业生产".equals(family.employment)){
                    agriculturalProduction ++;
                    familyEmployment += 0.8;
                    numberOfOver60_agriculturalProduction ++;
                }else if("务工".equals(family.employment)){
                    migrantWorkers ++;
                    familyEmployment += 0.8;
                    numberOfOver60_migrantWorkers ++;
                }else if("休业".equals(family.employment)){
                    closedDown ++;
                    numberOfOver60_closedDown ++;
                }else if("待业".equals(family.employment)){
                    unemployed ++;
                    numberOfOver60_unemployed ++;
                }

                if(isMajor(family)){
                    majorDiseases ++;
                    numberOfOver60_majorDiseases ++;
                    //重大疾病
                    numberOfOver60_major_disease_info = ArrayUtils.addAllStr(numberOfOver60_major_disease_info, family.major_disease_info);
                }else if(isChronic(family)){
                    chronicDiseases ++;
                    numberOfOver60_chronicDiseases ++;
                    //慢性疾病
                    numberOfOver60_chronic_disease_info = ArrayUtils.addAllStr(numberOfOver60_chronic_disease_info, family.chronic_disease_info);
                }else if(isDisabled(family)){
                    disability ++;
                    numberOfOver60_disability ++;
                    //残疾
                    numberOfOver60_disabled_info = ArrayUtils.addAllStr(numberOfOver60_disabled_info, family.disabled_info);
                }else {
                    good ++;
                    numberOfOver60_good ++;
                }

            }
        }

        return this;
    }

    //数据整理
    public HumanResourceStandardized dataCollated(){

        laborTotalPopulation = laborForce/totalPopulation;
        education = primary*6 + junior*9 + high*12 + collegeDegreeOrAbove*15;
        educationPer = education/totalPopulation;
        familyHealth = good + chronicDiseases*0.5;
        healthPer = familyHealth/totalPopulation;
        employmentPer = familyEmployment/totalPopulation;
        if(laborForce==0){
            mainForce = 0;
        }else {
            mainForce = mainLaborForce/laborForce;
        }

        //计算结果
        if(laborTotalPopulation >= 0.6){
            laborAssignment = 1;
        }else if(laborTotalPopulation >= 0.5){
            laborAssignment = 0.8;
        }else if(laborTotalPopulation >= 0.35){
            laborAssignment = 0.5;
        }else if(laborTotalPopulation >= 0.25){
            laborAssignment = 0.3;
        }else {
            laborAssignment = 0.1;
        }

        if(educationPer >= 9){
            educationalAssignment = 1;
        }else{
            educationalAssignment = educationPer/9;
        }

        if(healthPer >= 1){
            healthAssignment = 1;
        }else if(healthPer >= 0.75){
            healthAssignment = 0.8;
        }else if(healthPer >= 0.5){
            healthAssignment = 0.6;
        }else if(healthPer >= 0.2){
            healthAssignment = 0.2;
        }

        if(employmentPer >= 1){
            employmentAssignment = 1;
        }else if(employmentPer >= 0.75){
            employmentAssignment = 0.8;
        }else if(employmentPer >= 0.5){
            employmentAssignment = 0.6;
        }else if(employmentPer >= 0.2){
            employmentAssignment = 0.2;
        }

        mainForceAssignment = mainForce;
        if(numberOfAged19_602==0){
            disabilityRatio = 0;
        }else {
            disabilityRatio =  (double) disabledWorkers/numberOfAged19_602;
        }

        return this;
    }

    public static void main(String[] args) {
        FormOne on = new FormOne();
        on.user_age = 26;
        on.user_sex = "男";
        on.user_nation = "汉族";
        on.if_marriage = "已婚";
        on.education_level = "初中";
        on.total_people_num = 4;
        on.homestyle = "支出贫困低收入";

        on.family = new ArrayList<>();
        Family family1 = new Family();
        Family family2 = new Family();
        Family family3 = new Family();
        Family family4 = new Family();

        family1.age = "16岁以下";
        family1.sex = "男";
        family1.employment = "无";
        family1.education = "学龄前";
        family1.chronic_disease_info = new String[]{"慢性咽喉炎"};


        family2.age = "19-60";
        family2.sex = "男";
        family2.employment = "务工";
        family2.education = "小学";


        family3.age = "19-60";
        family3.sex = "女";
        family3.employment = "休业";
        family3.education = "初中";
        family3.chronic_disease_info = new String[]{"咽喉炎"};

        family4.age = "19-60";
        family4.sex = "女";
        family4.employment = "待业";
        family4.education = "大专及以上";

        family4.chronic_disease_info = new String[]{"咽喉炎"};


        on.family.add(family1);
        on.family.add(family2);
        on.family.add(family3);
        on.family.add(family4);

        on.bad_behavior = "没有";
        on.exit = "没有";

        HumanResourceStandardized h1 = new HumanResourceStandardized(on);

        System.out.println(h1);
        System.out.println(h1.healthPer);
    }

    public boolean isHealth(Family family) {

        if(isChronic(family)) return false;

        if(isMajor(family)) return false;

        if(isDisabled(family)) return false;

        return true;
    }

    public boolean isChronic(Family family){
        if (family.chronic_disease_info != null && family.chronic_disease_info.length != 0)
            return true;
        return false;
    }

    public boolean isMajor(Family family){
        if (family.major_disease_info != null && family.major_disease_info.length != 0)
            return true;
        return false;
    }

    public boolean isDisabled(Family family){
        if (family.disabled_info != null && family.disabled_info.length != 0)
            return true;
        return false;
    }
}
